//
//  BYFooterView.m
//  School+
//
//  Created by Sean Sebastian on 5/15/16.
//  Copyright © 2016 Sean Sebastian. All rights reserved.
//

#import "BYFooterView.h"

#import "masonry.h"

@interface BYFooterView ()

@property (nonatomic , weak) UIButton *logoutButton;
@property (nonatomic , weak) UIButton *adminLoginButton;

@end

@implementation BYFooterView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    [self prepareUI];
    return self;
}

- (void)prepareUI
{
    [self addSubview:self.logoutButton];
    [self addSubview:self.adminLoginButton];
    
    [self.logoutButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).with.offset(10);
        make.left.equalTo(self).with.offset(10);
        make.right.equalTo(self).with.offset(-10);
        make.height.mas_equalTo(@40);
    }];
    
    [self.adminLoginButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.logoutButton.mas_bottom).with.offset(10);
        make.width.equalTo(self.logoutButton);
        make.height.equalTo(self.logoutButton);
        make.left.equalTo(self).with.offset(10);
    }];
    
}

- (UIButton *)logoutButton
{
    if (_logoutButton == nil) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
        [btn setTitle:@"退出账户" forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn setBackgroundColor:[UIColor lightGrayColor]];
        [btn addTarget:self action:@selector(signOutClick) forControlEvents:UIControlEventTouchUpInside];
        _logoutButton = btn;
        return btn;
    }
    return _logoutButton;
}

- (UIButton *)adminLoginButton
{
    if (_adminLoginButton == nil) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
        [btn setTitle:@"登陆后台管理" forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn setBackgroundColor:[UIColor lightGrayColor]];
        [btn addTarget:self action:@selector(signInClick) forControlEvents:UIControlEventTouchUpInside];
        _adminLoginButton = btn;
        return btn;
    }
    return _adminLoginButton;
}

- (void)signOutClick
{
    [self.delegate logoutButtonClick];
}

- (void)signInClick
{
    [self.delegate adminLoginButtonClick];
}
@end
